package com.example.hello.slice;

import com.example.hello.ResourceTable;
import com.example.hello.RespAbility;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import wang.unclecat.actcaller.ActCaller;


public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        Text text = (Text) findComponentById(ResourceTable.Id_txtStatus);

        Button btn = (Button) findComponentById(ResourceTable.Id_btn);

        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(RespAbility.class)
                        .build();
                intent.setOperation(operation);

                ActCaller.startForResult(MainAbilitySlice.this, intent, new ActCaller.Callback() {
                    @Override
                    public void onAbilityResult(Intent result) {
                        text.setText(result.getStringParam("resultData"));
                    }
                });
            }
        });

    }

}
